<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Mammoth.js 示例</title>
</head>
<body>

  <h1>Word to HTML Converter with Mammoth.js</h1>

  <input type="file" id="fileInput" accept=".docx" />
  <div id="output"></div>

  <script src="https://cdnjs.cloudflare.com/ajax/libs/mammoth/1.4.17/mammoth.browser.min.js"></script>
  <script>
    document.getElementById('fileInput').addEventListener('change', function (event) {
      const file = event.target.files[0];
      if (file) {
        const reader = new FileReader();
        reader.onload = function (event) {
          const arrayBuffer = event.target.result;
          mammoth.convertToHtml({ arrayBuffer: arrayBuffer })
            .then(function (result) {
              const html = result.value; // Extracted HTML
              document.getElementById('output').innerHTML = html;
            })
            .catch(function (error) {
              console.error("Error converting Word document:", error);
            });
        };
        reader.readAsArrayBuffer(file);
      }
    });
  </script>

</body>
</html>